﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace drawDong
{
    public partial class Form10 : Form
    {
        private int mainColumns = 13;
        private string pathName = "";

        public Form10()
        {
            InitializeComponent();
        }

        private void Form5_Load(object sender, EventArgs e)
        {
            setSaveBoxName();
        }

        private void setSaveBoxName()
        {
            DirectoryInfo rootDir = new DirectoryInfo(GlobalVariables.fliterPath);
            FileInfo[] allDirs = rootDir.GetFiles();

            int si = allDirs.Length;
            int ct = si % mainColumns > 0 ? si / mainColumns + 1 : si / mainColumns;
            for (int i = 0; i < ct; i++)
            {
                this.dataGridView1.Rows.Add("", "", "", "", "", "", "");
            }

            int rows = this.dataGridView1.Rows.Count;
            int columns = mainColumns;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    string text = this.dataGridView1[j, i].Value == null ? "" : this.dataGridView1[j, i].Value.ToString();
                    Console.WriteLine(text);

                    int index = (rows - 1) * mainColumns + j;
                    if (index >= allDirs.Length)
                    {
                        break;
                    }
                    DataGridViewButtonCell xx = new DataGridViewButtonCell();
                    this.dataGridView1[j, i] = xx;
                    this.dataGridView1[j, i].Value = allDirs[index].Name.Replace(".txt", "");
                }
            }
        }

        public string getFilterName()
        {
            return pathName;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (null == this.dataGridView1[e.ColumnIndex, e.RowIndex].Value)
            {
                return;
            }
            pathName = this.dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
            button1.Visible = true;
            button2.Visible = false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (pathName.Length <= 0)
            {
                MessageBox.Show("请选择一个滤镜箱", "提示");
            }
        }
    }
}
